{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "5477b483",
   "metadata": {},
   "source": [
    "## 用户输入"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "92124aaf",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入您的账号：huanmian\n",
      "请输入您的密码：586566\n",
      "您输入的账号或密码不正确，请重新输入,您还有 2 次机会~~加油~~~\n",
      "请输入您的账号：juajisu\n",
      "请输入您的密码：859756\n",
      "您输入的账号或密码不正确，请重新输入,您还有 1 次机会~~加油~~~\n",
      "请输入您的账号：huanmin\n",
      "请输入您的密码：123456\n",
      "欢迎huanmin登录系统使用~\n"
     ]
    }
   ],
   "source": [
    "# anthor:huanmin\n",
    "# 时间：9.25week04\n",
    "\n",
    "# 登录系统\n",
    "# 用户输入的数据 VS 数据库的数据\n",
    "# 优化： 1.输入不正确时继续输入. 2.设置输入失败的次数\n",
    "\n",
    "# while True + count 计算器 VS for循环 + range()\n",
    "# 以下9行为例子：\n",
    "'''\n",
    "count = 0\n",
    "while True:\n",
    "    # count = count+1\n",
    "    count +=1\n",
    "    print(\"你是风儿我是沙，缠缠绵绵到天涯...\", count)\n",
    "    if count == 100:\n",
    "        break\n",
    "'''\n",
    "\n",
    "# 模拟数据库数据\n",
    "user_data = \"huanmin\"\n",
    "password_data = \"123456\"\n",
    "\n",
    "count = 3\n",
    "while True:\n",
    "    # 用户输入数据\n",
    "    username = input(\"请输入您的账号：\")\n",
    "    password = input(\"请输入您的密码：\")\n",
    "    count -= 1\n",
    "    # 1. 先判断账号\n",
    "    if username == user_data:\n",
    "        if password == password_data :\n",
    "            # 占位符%s\n",
    "            print(\"欢迎%s登录系统使用~\"%(username))\n",
    "            break\n",
    "        else:\n",
    "            if count == 0:\n",
    "             print(\"不是吧不是吧，都输了三次了还不对啊！别输了，2分钟之后再来吧\")\n",
    "             break\n",
    "            else:\n",
    "             print(\"您输入的账号或密码不正确，请重新输入,您还有\", count, \"次机会~~加油~~~\")\n",
    "    else:\n",
    "        if count == 0:\n",
    "            print(\"不是吧不是吧，都输了三次了还不对啊！别输了，2分钟之后再来吧\")\n",
    "            break\n",
    "        else:\n",
    "            print(\"您输入的账号或密码不正确，请重新输入,您还有\", count, \"次机会~~加油~~~\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "46210045",
   "metadata": {},
   "source": [
    "## 用户输入和格式化打印"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e79b373c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "name: huanmin\n",
      "age: 11\n",
      "job: student\n",
      "salary: 0\n",
      "-----------INFOhuanmin----------\n",
      "name:huanmin\n",
      "age:11\n",
      "job:student\n",
      "salary:0\n",
      "-----------INFO huanmin----------\n",
      "name:huanmin\n",
      "age:11\n",
      "job:student\n",
      "salary:0\n",
      "-----------INFOhuanmin----------\n",
      "name:huanmin\n",
      "age:11\n",
      "job:student\n",
      "salary:0\n",
      "https://www.nfu.edu.cn/ztb/index1.htm\n",
      "https://www.nfu.edu.cn/ztb/index2.htm\n",
      "https://www.nfu.edu.cn/ztb/index3.htm\n",
      "https://www.nfu.edu.cn/ztb/index4.htm\n",
      "https://www.nfu.edu.cn/ztb/index5.htm\n",
      "https://www.nfu.edu.cn/ztb/index6.htm\n",
      "https://www.nfu.edu.cn/ztb/index7.htm\n",
      "https://www.nfu.edu.cn/ztb/index8.htm\n",
      "https://www.nfu.edu.cn/ztb/index9.htm\n",
      "https://www.nfu.edu.cn/ztb/index10.htm\n",
      "https://www.nfu.edu.cn/ztb/index11.htm\n",
      "https://www.nfu.edu.cn/ztb/index12.htm\n",
      "https://www.nfu.edu.cn/ztb/index13.htm\n",
      "https://www.nfu.edu.cn/ztb/index14.htm\n",
      "https://www.nfu.edu.cn/ztb/index15.htm\n",
      "https://www.nfu.edu.cn/ztb/index16.htm\n",
      "https://www.nfu.edu.cn/ztb/index17.htm\n",
      "https://www.nfu.edu.cn/ztb/index18.htm\n",
      "https://www.nfu.edu.cn/ztb/index19.htm\n",
      "https://www.nfu.edu.cn/ztb/index20.htm\n",
      "https://www.nfu.edu.cn/ztb/index21.htm\n",
      "https://www.nfu.edu.cn/ztb/index22.htm\n",
      "https://www.nfu.edu.cn/ztb/index23.htm\n",
      "https://www.nfu.edu.cn/ztb/index24.htm\n",
      "https://www.nfu.edu.cn/ztb/index25.htm\n",
      "https://www.nfu.edu.cn/ztb/index26.htm\n"
     ]
    }
   ],
   "source": [
    "# anthor:huanmin\n",
    "# 时间：10.8week05\n",
    "# 主要知识：列表入门\n",
    "\n",
    "# 用户输入和格式化打印\n",
    "name = input(\"name: \")\n",
    "age = input(\"age: \")\n",
    "job = input(\"job: \")\n",
    "salary = input(\"salary: \")\n",
    "\n",
    "# name 动态的出现在字符中，字符串的拼接 用“+”符号来拼接\n",
    "info = '''-----------INFO'''+ name+'''----------\n",
    "name:'''+name+'''\n",
    "age:'''+age+'''\n",
    "job:'''+job+'''\n",
    "salary:'''+salary\n",
    "\n",
    "print(info)\n",
    "\n",
    "# 优化：字符串的拼接: 占位符%s动态的数据——>变量\n",
    "# 优势：1、全部都写在一个大的字符串里面了 2、省略了 “+”符号\n",
    "# 缺点：如果有几百个需要填进去的内容，容易顺序乱掉。出现打印结果的不正确。\n",
    "info_占位符 = '''-----------INFO %s----------\n",
    "name:%s\n",
    "age:%s\n",
    "job:%s\n",
    "salary:%s''' %(name, name, age, job, salary)\n",
    "\n",
    "print(info_占位符)\n",
    "\n",
    "# 优化： .format() 格式化 字符串\n",
    "info_format ='''-----------INFO{姓名}----------\n",
    "name:{姓名}\n",
    "age:{年龄}\n",
    "job:{工作}\n",
    "salary:{薪水}'''.format(姓名=name, 年龄=age, 工作=job, 薪水=salary)\n",
    "\n",
    "print(info_format)\n",
    "\n",
    "# .format()案例\n",
    "url =\"https://www.nfu.edu.cn/\" #官网的域名\n",
    "# 目标获取高教动态的所有url链接\n",
    "高教动态 = \"gjdt\"\n",
    "url_页面 = \".htm\"\n",
    "url_页面细节不变 = \"/index\"\n",
    "\n",
    "# for i in range(1,27):\n",
    "#   完整的高教动态所有页面url =url+高校动态+ url_页面细节不变 + str(i)+url_页面\n",
    "#   print(完整的高教动态所有页面url)\n",
    "\n",
    "for i in range(1, 27):\n",
    "    完整的高教动态所有页面url = \"https://www.nfu.edu.cn/{新闻}/index{页码}.htm\".format(页码=str(i), 新闻=\"ztb\")\n",
    "    print(完整的高教动态所有页面url)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ef11c031",
   "metadata": {},
   "source": [
    "## 列表入门"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "3945d017",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "u\n",
      "['heyuncheng', 589685, 17]\n"
     ]
    }
   ],
   "source": [
    "# 列表入门\n",
    "user_data = \"huanmin||pengyuyan||wuyanzu||kuli\"\n",
    "print(user_data[1])\n",
    "\n",
    "# 引入列表\n",
    "user_data_list = [[\"huanmin\", 123456,11], [\"jojo\",147898,18], [\"heyuncheng\",589685,17], [\"hhh\",789789,12]]\n",
    "password_list = [123456,147898,589685,789789]\n",
    "age = [11,18,17,12]\n",
    "\n",
    "# 1. 从左往右取值（index & slice）\n",
    "print(user_data_list[2]) "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c3e75c82",
   "metadata": {},
   "source": [
    "* user_data_list[2]表示取这个列表的第三个值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "da1cd459",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[['huanmin', 123456, 11], ['jojo', 147898, 18], ['heyuncheng', 589685, 17]]\n"
     ]
    }
   ],
   "source": [
    "# 切片 slice ，右边的值取不到 例如[0:3] 索引为3的值取不到\n",
    "print(user_data_list[0:3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "3958d079",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[['huanmin', 123456, 11], ['jojo', 147898, 18], ['heyuncheng', 589685, 17]]\n"
     ]
    }
   ],
   "source": [
    "# 当从0开始取值时，0 可以忽略不写\n",
    "print(user_data_list[:3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "29c079fd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['heyuncheng', 589685, 17]\n"
     ]
    }
   ],
   "source": [
    "# -3，-2，-1，0，1，2，3，4..\n",
    "# 2. 从右往左取值(index & slice)\n",
    "print(user_data_list[-2])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8f2951ab",
   "metadata": {},
   "source": [
    "* user_data_list[-2]表示从右往左取值，第二个"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "321d7cf8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[['jojo', 147898, 18], ['heyuncheng', 589685, 17]]\n"
     ]
    }
   ],
   "source": [
    "# 切片 slice ，右边的值取不到 例如[-3:-1] 索引为-1的值取不到\n",
    "print(user_data_list[-3:-1])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8444a5d9",
   "metadata": {},
   "source": [
    "* user_data_list[-3:-1]表示从右往左取第二和第三个值，最右边取不到"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "2264d4bd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[]\n"
     ]
    }
   ],
   "source": [
    "# 如果取值为空：说明slice写错了 例如[-3:0]\n",
    "# 如果要取到最后一个值，不能写0，直接省略不写\n",
    "print(user_data_list[-3:0])  # 错误情况"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "e49fd784",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[['jojo', 147898, 18], ['heyuncheng', 589685, 17], ['hhh', 789789, 12]]\n"
     ]
    }
   ],
   "source": [
    "print(user_data_list[-3:])   # 正确情况"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "75681de7",
   "metadata": {},
   "source": [
    "* user_data_list[-3:]表示依次从右往左取第三个值、第二个值、第一个值"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3b4720e9",
   "metadata": {},
   "source": [
    "###### ****重要！！！！！！！！****"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "3c960803",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[['huanmin', 123456, 11], ['jojo', 147898, 18], ['heyuncheng', 589685, 17], ['hhh', 789789, 12]]\n"
     ]
    }
   ],
   "source": [
    "print(user_data_list[:])  # 列出列表全部内容"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "94e177ac",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[['heyuncheng', 589685, 17], ['hhh', 789789, 12]]\n"
     ]
    }
   ],
   "source": [
    "print(user_data_list[2:])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "78ae01d7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[]\n"
     ]
    }
   ],
   "source": [
    "print(user_data_list[3:1])  # 这种情况为错误"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "5ae28a57",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n",
      "[0, 2, 4]\n"
     ]
    }
   ],
   "source": [
    "# 步长，list列表slice ：[start:stop:step]\n",
    "'''\n",
    "如果没有指定开始值，则默认为0；\n",
    "如果没有指定结束指，则取列表允许的最大值；\n",
    "如果没有指定步长值，则默认步长为1.\n",
    "'''\n",
    "num = list(range(10))\n",
    "print(num)\n",
    "print(num[0:6:2])# 这里表示从0开始取，隔两个数取，6取不到"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3e4fcc85",
   "metadata": {},
   "source": [
    "## 练习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "c9b21f5a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 1, 2, 3, 4]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "1cefbb16",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[5, 6, 7, 8, 9]"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(5,10))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "8c602d6d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 2, 4, 6, 8]"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(0,10,2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "887b9246",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[10, 8, 6, 4]"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(10,2,-2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "b9fda3f0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(10,0,2))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d561580d",
   "metadata": {},
   "source": [
    "* 上面是错误的"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "c6d63eb8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[99,\n",
       " 98,\n",
       " 97,\n",
       " 96,\n",
       " 95,\n",
       " 94,\n",
       " 93,\n",
       " 92,\n",
       " 91,\n",
       " 90,\n",
       " 89,\n",
       " 88,\n",
       " 87,\n",
       " 86,\n",
       " 85,\n",
       " 84,\n",
       " 83,\n",
       " 82,\n",
       " 81,\n",
       " 80,\n",
       " 79,\n",
       " 78,\n",
       " 77,\n",
       " 76,\n",
       " 75,\n",
       " 74,\n",
       " 73,\n",
       " 72,\n",
       " 71,\n",
       " 70,\n",
       " 69,\n",
       " 68,\n",
       " 67,\n",
       " 66,\n",
       " 65,\n",
       " 64,\n",
       " 63,\n",
       " 62,\n",
       " 61,\n",
       " 60,\n",
       " 59,\n",
       " 58,\n",
       " 57,\n",
       " 56,\n",
       " 55,\n",
       " 54,\n",
       " 53,\n",
       " 52,\n",
       " 51,\n",
       " 50,\n",
       " 49,\n",
       " 48,\n",
       " 47,\n",
       " 46,\n",
       " 45,\n",
       " 44,\n",
       " 43,\n",
       " 42,\n",
       " 41,\n",
       " 40,\n",
       " 39,\n",
       " 38,\n",
       " 37,\n",
       " 36,\n",
       " 35,\n",
       " 34,\n",
       " 33,\n",
       " 32,\n",
       " 31,\n",
       " 30,\n",
       " 29,\n",
       " 28,\n",
       " 27,\n",
       " 26,\n",
       " 25,\n",
       " 24,\n",
       " 23,\n",
       " 22,\n",
       " 21,\n",
       " 20,\n",
       " 19,\n",
       " 18,\n",
       " 17,\n",
       " 16,\n",
       " 15,\n",
       " 14,\n",
       " 13,\n",
       " 12,\n",
       " 11,\n",
       " 10,\n",
       " 9,\n",
       " 8,\n",
       " 7,\n",
       " 6,\n",
       " 5,\n",
       " 4,\n",
       " 3,\n",
       " 2,\n",
       " 1]"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(99,0,-1))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.0b3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
